package de.wuertz.map.examples;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import de.wuertz.map.enumeration.Color;
import de.wuertz.map.enumeration.MarkerSize;
import de.wuertz.map.exception.InvalidParameterException;
import de.wuertz.map.exception.URLOverlengthException;
import de.wuertz.map.types.Coordinate;
import de.wuertz.map.types.Marker;
import de.wuertz.map.url.GoogleStaticMapsUrlGenerator;

/**
 * This example just shows a simple map in a window.
 * 
 * @author Christian Würtz <christian.wuertz@googlemail.com>
 */
public class HelloMarker
{
	/**
	 * Start this example.
	 * 
	 * @param args
	 *           The command-line arguments.
	 */
	public static void main(String[] args)
	{
		try
		{
			// Generate the URL.
			GoogleStaticMapsUrlGenerator generator = new GoogleStaticMapsUrlGenerator();
			generator.setMapDimensions(640, 640);
			generator.setZoomLevel((short) 16);
			generator.setCenter(new Coordinate(52.5163057394391, 13.3777213096619));

			// Add a marker.
			Marker marker = new Marker(new Coordinate(52.5163057394391, 13.3777213096619));
			marker.setColor(Color.BLUE);
			marker.setLabel('A');
			marker.setSize(MarkerSize.MID);
			generator.addMarker(marker);

			// Download the map.
			BufferedImage image = ImageIO.read(generator.generateURL());

			// Show the map in a frame.
			JLabel label = new JLabel(new ImageIcon(image));
			JFrame f = new JFrame();
			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			f.getContentPane().add(label);
			f.pack();
			f.setLocation(200, 200);
			f.setVisible(true);
		}
		catch (InvalidParameterException e)
		{
			e.printStackTrace();
		}
		catch (MalformedURLException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		catch (URLOverlengthException e)
		{
			e.printStackTrace();
		}
	}
}
